home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / terminal / tpk_182 / comphdr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  3.6 KB  |  200 lines

  1. /*
  2. COMPHDR.C
  3.  
  4. Ce programme est un serveur pour TPK. Il remplace les lignes R: du debut
  5. du message par la liste des BBS empruntees par le message. Le format est
  6. identique a celui des BBS: "Path: !F6XYZ!etc...."
  7.  
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13.  
  14. int ReadDest (char *cmd);
  15. int ReadFromBbs (char *cmd);
  16.  
  17. char str[256];
  18. char line[256];
  19. char LastHdr[81];
  20. char Path_Tpk[129];
  21. char FiMsg[129];
  22. char FiMsgBak[129];
  23. char N_Mycall[7]="\0";
  24. char N_To[7]="\0";
  25. char N_From[7]="\0";
  26. char N_Bbs[7]="\0";
  27. char Typ[2],To[7],From[7],Abbs[41],Bid[13],BidOrg[13];
  28. char Fbbs[41],FbbsCall[7];
  29. char Subject[81];
  30.  
  31. void main(int argc, char *argv[])
  32. {
  33. FILE *fichin,*fichout;
  34. char *s;
  35. char *ptr;
  36. char *ptr_path;
  37. char str_path[1000];
  38. int WaitFrom,Nbcar;
  39.  
  40. /* Le premier parametre est le nom du fichier contenant le message */
  41.  
  42. strncpy(FiMsg, argv[1], 128);
  43. strcpy(FiMsgBak, FiMsg);
  44. strcat(FiMsgBak, ".BAK");
  45.  
  46. /* Le deuxieme parametre est le repertoire de TPK */
  47.  
  48. strncpy(Path_Tpk, argv[2], 128);
  49.  
  50. /* Le troisieme parametre est l'indicatif utilise */
  51.  
  52. strncpy(N_Mycall, argv[3], 6);
  53.  
  54. if ((rename(FiMsg, FiMsgBak)) == 0)
  55.     {
  56.     if ((fichin=fopen(FiMsgBak, "r")) != NULL)
  57.         {
  58.         if ((fichout=fopen(FiMsg, "w")) != NULL)
  59.             {
  60.             if (fgets(line, 255, fichin) != NULL)
  61.                 {
  62.                 ReadDest (line);
  63.                 fputs(line, fichout);
  64.                 if (fgets(Subject, 80, fichin) != NULL)
  65.                     {
  66.                     fputs(Subject, fichout);
  67.                     WaitFrom=1;
  68.                     sprintf(str_path, "Path: ");
  69.                     Nbcar=6;
  70.                     ptr_path=str_path+6;
  71.                     while (fgets(line, 255, fichin) != NULL)
  72.                         {
  73.                         if (WaitFrom)
  74.                             {
  75.                             if ((s=strstr(line, "R:")) != NULL)
  76.                                 {
  77.                                 strcpy(LastHdr, line);
  78.                                 if (ReadFromBbs (s))
  79.                                     {
  80.                                     ptr=str;
  81.                                     *ptr++='!';
  82.                                     for (s=Fbbs; *s != '.'; s++ ) *ptr++=*s;
  83.                                     *ptr='\0';
  84.                                     Nbcar+=strlen(str);
  85.                                     sprintf(ptr_path, str);
  86.                                     ptr_path+=strlen(str);
  87.                                     if (Nbcar>72)
  88.                                         {
  89.                                         sprintf(ptr_path, "\n      ");
  90.                                         ptr_path+=7;
  91.                                         Nbcar=7;
  92.                                         }
  93.                                     }
  94.                                 }
  95.                             else
  96.                                 {
  97.                                 WaitFrom--;
  98.                                 fputs(LastHdr, fichout);
  99.                                 fputs(str_path,fichout);
  100.                                 if (Nbcar) fputs("\n", fichout);
  101.                                 }
  102.                             }
  103.                         else
  104.                             fputs(line, fichout);
  105.                         }
  106.                     }
  107.                 }
  108.             fclose(fichout);
  109.             }
  110.         fclose(fichin);
  111.         }
  112.         remove(FiMsgBak);
  113.     }
  114. }
  115.  
  116. /* Lecture des informations dans une ligne de commande SP ou SB */
  117.  
  118. int ReadDest (char *cmd)
  119. {
  120. char *s;
  121. char *ptr;
  122. int i;
  123.  
  124. if (strlen(cmd)>2)
  125.     {
  126.     if (toupper(*cmd)==83)
  127.         {
  128.         s=cmd;
  129.         s=strupr(s);
  130.         *Typ=*++s;
  131.         ptr=To;                 /* TO */
  132.         i=6;
  133.         for (++s;*s ;s++)
  134.             {
  135.             if (*s==64){        /* @BBS*/
  136.                 ptr=Abbs;
  137.                 *ptr=0;
  138.                 i=40;}
  139.             else if (*s==60){   /* <FROM */
  140.                 ptr=From;
  141.                 *ptr=0;
  142.                 i=6;}
  143.             else if (*s==36){   /* $BID */
  144.                 ptr=Bid;
  145.                 *ptr=0;
  146.                 i=12;}
  147.             else if (*s<33)
  148.                 continue;
  149.             else if (i)
  150.                 {
  151.                 if (*s>32)
  152.                     {
  153.                     *ptr++=*s;
  154.                     *ptr=0;
  155.                     i--;
  156.                     }
  157.                 }
  158.             }
  159.             return strlen(To);
  160.         }
  161.     }
  162. }
  163.  
  164. /* Recherche de la BBS d'origine du message dans une ligne R: */
  165.  
  166. int ReadFromBbs (char *cmd)
  167. {
  168. char *s;
  169. char *ptr;
  170. int i=0;
  171. for (s=cmd; *s; s++)
  172.     {
  173.     if (*s==64){
  174.         ptr=Fbbs;
  175.         *ptr=0;
  176.         i=40;
  177.         }
  178.     else if (*s==36){
  179.         ptr=BidOrg;
  180.         *ptr=0;
  181.         i=12;
  182.         }
  183.     else if (*s==58)
  184.         continue;
  185.     else if (*s==32)
  186.         i=0;
  187.     else if (i)
  188.         {
  189.         if (*s>32)
  190.             {
  191.             *ptr++=*s;
  192.             *ptr=0;
  193.             i--;
  194.             }
  195.         }
  196.     }
  197. return strlen(Fbbs);
  198. }
  199.  
  200.